package cz.proks.easyhelpdesk.gwt.event;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

import cz.proks.easyhelpdesk.api.model.Filter;

public class FilterChangeEvent extends GwtEvent<FilterChangeEvent.Handler> {
    
    public static Type<Handler> TYPE = new Type<FilterChangeEvent.Handler>();
    
    public static interface Handler extends EventHandler {
        void onFilterChange(FilterChangeEvent event);
    }
    
    private final Filter filter;
    
    public FilterChangeEvent(Filter filter) {
        this.filter = filter;
    }
       
    public Filter getNewFilter() {
        return filter;
    }
    
    public static void fireEvent(HasFilterChangeHandlers source, Filter newFilter) {
        source.fireEvent(new FilterChangeEvent(newFilter));
    }

    @Override
    public Type<Handler> getAssociatedType() {
        return TYPE;
    }

    @Override
    protected void dispatch(Handler handler) {
        handler.onFilterChange(this);
    }
}
